<?php
namespace service;

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

/**
 * 日志记录
 * Class MyLog
 * @package service
 */
class MyLog {
    /**
     * @param array $content    记录日志内容
     * @param string $msg       The log message
     * @param string $name      The logging channel
     * @param string $path      日志位置
     * @param int $level        日志等级
     */
    public static function setLog($content = [] , $msg = "" ,$name = "log",$path = "./log/log.log",$level = Logger::INFO) {
        // create a log channel
        $log = new Logger($name);
        $stream_handler = new StreamHandler($path, Logger::DEBUG); // 过滤级别
        $log->pushHandler($stream_handler);

        // add records to the log
        switch (strtoupper($level)) {
            case Logger::DEBUG:
            case 1:
            case "DEBUG":
                $log->debug($msg,$content);
                break;
            case Logger::INFO:
            case 2:
            case "INFO":
                $log->info($msg,$content);
                break;
            case Logger::NOTICE:
            case 3:
            case "NOTICE":
                $log->notice($msg,$content);
                break;
            case Logger::WARNING:
            case 4:
            case "WARNING":
                $log->warning($msg,$content);
                break;
            case Logger::ERROR:
            case 5:
            case "ERROR":
                $log->error($msg,$content);
                break;
            case Logger::CRITICAL:
            case 6:
            case "CRITICAL":
                $log->critical($msg,$content);
                break;
            case Logger::ALERT:
            case 7:
            case "ALERT":
                $log->alert($msg,$content);
                break;
            case Logger::EMERGENCY:
            case 8:
            case "EMERGENCY":
                $log->emergency($msg,$content);
                break;
            default:
                $log->debug($msg,$content);
        }
    }
}
